package com.cmc.cloud.cmclink.doc.controller.admin.multimodaltransport;

import com.cmc.cloud.cmclink.doc.api.document.emums.ExImTypeEnum;
import com.cmc.cloud.cmclink.doc.api.document.emums.MulitOpOperationTypeEnum;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.rpcservice.CustomerRpcService;
import com.cmc.cloud.cmclink.doc.service.multimodaltransport.MultiOpService;
import com.cmc.cloud.cmclink.doc.vo.multimodaltransport.multiop.*;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 多式联运设置信息，前端接口Controller
 * 根据类型单独出接口 各种类型的校验、页面、权限、逻辑、日志均不相同，不可放在一个接口中
 * @author codegen
 */
@Tag(name = "管理后台 - 多式联运设置信息")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/multi-op")
public class MultiOpController {

    @Resource
    private MultiOpService multiOpService;
    @Resource
    private CustomerRpcService nameTransferService;

//    @Operation(summary = "创建多式联运代理设置信息，发送邮件记录")
//	@PostMapping("/create")
//    @PreAuthorize("@ss.hasPermission('doc:multi-op:create')")
//    public CommonResult<Void> createMultiOp(@Valid @RequestBody MultiOpCreateReqVO createReqVO) {
//        multiOpService.createMultiOp(createReqVO);
//        return CommonResult.success();
//    }
//
//    @Operation(summary = "更新多式联运代理设置信息，发送邮件记录")
//	@PostMapping("/update")
//    @PreAuthorize("@ss.hasPermission('doc:multi-op:update')")
//    public CommonResult<Void> updateMultiOp(@Valid @RequestBody MultiOpUpdateReqVO updateReqVO) {
//        multiOpService.updateMultiOp(updateReqVO);
//        return CommonResult.success();
//    }
//
//    @Operation(summary = "删除多式联运代理设置信息，发送邮件记录")
//	@PostMapping("/delete/{id}")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('doc:multi-op:delete')")
//    public CommonResult<Void> deleteMultiOp(@PathVariable("id") Long id) {
//        multiOpService.deleteMultiOp(id);
//        return CommonResult.success();
//    }
//
//    @Operation(summary = "获得多式联运代理设置信息，发送邮件记录")
//	@GetMapping("/get/{id}")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('doc:multi-op:query')")
//    public CommonResult<MultiOpRespVO> getMultiOp(@PathVariable("id") Long id) {
//        MultiOpDO multiOp = multiOpService.getMultiOp(id);
//        return CommonResult.success(MultiOpConvert.INSTANCE.convert(multiOp));
//    }
//
//    @Operation(summary = "获得多式联运代理设置信息，发送邮件记录列表")
//	@GetMapping("/list")
//    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
//    @PreAuthorize("@ss.hasPermission('doc:multi-op:query')")
//    public CommonResult<List<MultiOpRespVO>> getMultiOpList(@RequestParam("ids") Collection<Long> ids) {
//        List<MultiOpDO> list = multiOpService.getMultiOpList(ids);
//        return CommonResult.success(MultiOpConvert.INSTANCE.convertList(list));
//    }
//
//    @Operation(summary = "获得多式联运代理设置信息，发送邮件记录分页")
//	@GetMapping("/page")
//    @PreAuthorize("@ss.hasPermission('doc:multi-op:query')")
//    public CommonResult<PageResult<MultiOpRespVO>> getMultiOpPage(@Valid MultiOpPageReqVO pageVO) {
//        PageResult<MultiOpDO> pageResult = multiOpService.getMultiOpPage(pageVO);
//        List<MultiOpRespVO> results = MultiOpConvert.INSTANCE.convertList(pageResult.getList());
//        return CommonResult.success(new PageResult<>(results,pageResult.getTotal()));
//    }

    /**
     * 根据类型单独出接口 各种类型的校验、页面、权限、逻辑、日志均不相同，不可放在一个接口中
     * @param pageVo
     * @return
     */
    @Operation(summary = "ex 获得分页 Custom Broker:报关公司")
    @PostMapping("/ex/pageCustomBroker")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<MultiOpCustomBrokerRespVO>>
    pageCustomBroker(@Valid @RequestBody MultiOpCustomBrokerPageReqVO pageVo) {
        PageResult<MultiOpCustomBrokerRespVO> pageResult = multiOpService.pageCustomBroker(pageVo,ExImTypeEnum.EX);
        List<MultiOpCustomBrokerRespVO> results = pageResult.getList();
        nameTransferService.fillCompanyNameByBkpCodeFunctionally(
                results,
                // 提取bkpCode的函数
                MultiOpCustomBrokerRespVO::getCustomBroker,
                // 设置本地名称的函数
                MultiOpCustomBrokerRespVO::setCompanyNameLocal,
                // 设置英文名称的函数
                MultiOpCustomBrokerRespVO::setCompanyNameEn
        );
        return CommonResult.success(pageResult);
    }

    @Operation(summary = "进口-按时间段查找进口提单")
    @PostMapping("/querySumByTime")
    public CommonResult<List<MultiOpSumRespVO>> querySumByTime(@Valid @RequestBody MultiOpSumReqVO req) {
        return CommonResult.success(multiOpService.querySumByTime(req));
    }

    /**
     * 根据类型单独出接口 各种类型的校验、页面、权限、逻辑、日志均不相同，不可放在一个接口中
     *
     * @param updateContentReqVO
     * @return
     */
    @Operation(summary = "ex Set Custom Broker:报关公司")
    @PostMapping("/ex/updateCustomBroker")
    public CommonResult<Void>
    updateCustomBroker(@Valid @RequestBody MultiOpUpdateContentReqVO updateContentReqVO) {
        multiOpService.setOp(updateContentReqVO.getBlnoIds(),updateContentReqVO.getContent(),null,null, MulitOpOperationTypeEnum.CUSTOM_BROKER, ExImTypeEnum.EX);
        return CommonResult.success();
    }

    @Operation(summary = "ex Set Custom Broker:报关公司 Check")
    @PostMapping("/ex/checkCustomBroker")
    public CommonResult<List<MultiOpCheckMsgReqVO>>
    checkCustomBroker(@Valid @RequestBody MultiOpUpdateContentReqVO updateContentReqVO) {
        return CommonResult.success(multiOpService.checkOp(updateContentReqVO.getBlnoIds(), updateContentReqVO.getContent(), MulitOpOperationTypeEnum.CUSTOM_BROKER,ExImTypeEnum.EX));
    }

    /**
     * 根据类型单独出接口 各种类型的校验、页面、权限、逻辑、日志均不相同，不可放在一个接口中
     * @param pageVo
     * @return
     */
    @OperateLog(type = OperateTypeEnum.GET)
    @Operation(summary = "im 获得分页 进口-设置驳船代理报关公司")
    @PostMapping("/im/pageBargeAgentBroker")
    public CommonResult<PageResult<MultiOpBargeAgentBrokerRespVO>>
    imPageBargeAgentBroker(@Valid @RequestBody MultiOpBargeAgentBrokerPageReqVO pageVo) {
        PageResult<MultiOpBargeAgentBrokerRespVO> pageResult = multiOpService.imPageBargeAgentBroker(pageVo);
        return CommonResult.success(pageResult);
    }


}
